/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package GUI;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import Algorithm.*;

/**
 * 主文件，main函数入口，这个类继承了JFrame类
 *
 * @author ErikLee
 * @version 1.0
 */
public class MainFrame extends JFrame {
    JButton buttonNewGame;
    JPanel buttonPanel, statePanel;
    BoardPanel boardPanel = new BoardPanel();
    JLabel labelComputer, labelHuman;
    Icon iconComputer, iconHuman;

    /**
     * 构造函数
     *
     * @param frameTitle 窗口标题
     */
    public MainFrame(String frameTitle) {
        super(frameTitle);
        setLayout(new BorderLayout());
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        this.add(boardPanel, BorderLayout.CENTER);

        buttonNewGame = new JButton("新棋局");
        

        buttonPanel = new JPanel();
        buttonPanel.add(buttonNewGame);       
        
        statePanel = new JPanel();
        statePanel.setLayout(new GridLayout(3,1));
        iconComputer = new ImageIcon("pic/computer.png");
        iconHuman = new ImageIcon("pic/human.gif");
        labelComputer = new JLabel(iconComputer);
        labelHuman = new JLabel(iconHuman);

        statePanel.add(labelComputer);
        statePanel.add(labelHuman);
        statePanel.add(buttonPanel);
        this.add(statePanel, BorderLayout.EAST);

        buttonListener listener = new buttonListener();
        buttonNewGame.addActionListener(listener);
        

        this.pack();
        this.setLocationRelativeTo(null);
        this.setVisible(true);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new MainFrame("井字棋算法测试 - By 李强");
    }

    public class buttonListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            if(e.getSource() == buttonNewGame) {
                //New Game
            }
            if(e.getSource() == buttonNewGame) {
                boardPanel.restBoard();
            }
        }
    }
}